import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import { Plugin as importToCDN } from 'vite-plugin-cdn-import'
// https://vitejs.dev/config/
export default defineConfig({
    base: "./",
    plugins: [
        // 部分组件没有加载 很奇怪
        // importToCDN({
        //     modules: [
        //         {
        //             name: 'vue',
        //             var: 'Vue',
        //             path: 'https://unpkg.com/vue@3.2.13/dist/vue.global.prod.js'
        //         },
        //         {
        //             name: 'vue-router',
        //             var: 'VueRouter',
        //             path: 'https://unpkg.com/vue-router@4.0.0/dist/vue-router.global.js'
        //         },
        //         {
        //             name: 'naive-ui',
        //             var: 'naive',
        //             path: 'https://unpkg.com/naive-ui@2.40.3/dist/index.js'
        //         },
        //         {
        //             name: 'xe-utils',
        //             var: 'XEUtils',
        //             path: 'https://unpkg.com/xe-utils@3.5.32/dist/xe-utils.umd.min.js'
        //         }
        //     ]
        // }),
        vue(),
        AutoImport({
            enabled: false, // 是否自动生成 eslint 规则，建议生成之后设置 false
            dts: false,
            // dts: "src/auto-imports.d.ts", // 生成 TypeScript 声明文件
            imports: [
                "vue",
                "vue-router",
                {
                    "naive-ui": [
                        "useDialog",
                        "useMessage",
                        "useNotification",
                        "useLoadingBar",
                    ],
                },
            ],
        }),
        Components({
            resolvers: [NaiveUiResolver()],
        }),

    ],
    resolve: {
        alias: {
            "@": path.resolve(__dirname, "src"),
        },
    },
    server: {
        host: true,
        // open: true,
        port: 4000,
    }
});
